/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.patrol.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.patrol.APatrolBillDetail;
import com.thor.palmmall.spi.device.SDeviceInspectDetail;

/**
 * @author wolv
 *
 */
public class APatrolBillDetailConverter implements Converter<SDeviceInspectDetail, APatrolBillDetail> {

	public static APatrolBillDetailConverter getInstance() {
		if (instance == null)
			instance = new APatrolBillDetailConverter();
		return instance;
	}

	private static APatrolBillDetailConverter instance;

	private APatrolBillDetailConverter() {
	}

	@Override
	public APatrolBillDetail convert(SDeviceInspectDetail source) {
		if (source == null)
			return null;

		APatrolBillDetail target = new APatrolBillDetail();
		target.setDevice(UCN.newInstance(source.getDevice()));
		if (source.getItems() != null) {
			target.setItems(new ArrayList<KV>());
			for (KV sourceKV : source.getItems())
				target.getItems().add(KV.newInstance(sourceKV));
		}
		target.setLineNo(source.getLineNo());

		return target;
	}

}
